Skip to content

chore(storage): support PartSizeHint and optimize cleanup#19930

Open
cpriti-os wants to merge 4 commits into
googleapis:mainfrom
cpriti-os:pcu-improve
Open

chore(storage): support PartSizeHint and optimize cleanup#19930
cpriti-os wants to merge 4 commits into
googleapis:mainfrom
cpriti-os:pcu-improve

Conversation

@cpriti-os

Copy link
Copy Markdown
Contributor

No description provided.

@cpriti-os
cpriti-os requested review from a team as code owners June 9, 2026 05:42
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Jun 9, 2026
@cpriti-os
cpriti-os requested a review from krishnamd-jkp June 9, 2026 05:42

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request renames PartSize to PartSizeHint in ParallelUploadConfig, increases the minimum part size from 5 MiB to 8 MiB, and updates the associated tests. It also optimizes cleanup by enabling automatic deletion of source objects during compose operations (DeleteSourceObjects = true) and updating the local cleanup logic to run only when an upload fails and the final compose does not succeed. Feedback was provided regarding the background cleanup goroutine, which currently uses the potentially canceled parent context. To prevent temporary object leaks when a context is canceled, it is recommended to use context.WithoutCancel for the cleanup operation.

Comment thread storage/pcu.go
Comment on lines 445 to 453
defer func() {
go s.doCleanupFn(s)
s.mu.Lock()
hasErr := s.firstErr != nil
finalSucceeded := s.finalComposeSucceeded
s.mu.Unlock()
if hasErr && !finalSucceeded {
go s.doCleanupFn(s)
}
}()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When the parent context is canceled, the background cleanup goroutine go s.doCleanupFn(s) will run using the canceled context s.ctx. This causes all subsequent GCS API calls (such as deleting temporary objects) to fail immediately with context.Canceled, resulting in leaked temporary objects in the bucket.

To prevent this, use context.WithoutCancel to ensure the cleanup operation is not prematurely terminated when the parent context is canceled.

Suggested change
defer func() {
go s.doCleanupFn(s)
s.mu.Lock()
hasErr := s.firstErr != nil
finalSucceeded := s.finalComposeSucceeded
s.mu.Unlock()
if hasErr && !finalSucceeded {
go s.doCleanupFn(s)
}
}()
defer func() {
s.mu.Lock()
hasErr := s.firstErr != nil
finalSucceeded := s.finalComposeSucceeded
s.mu.Unlock()
if hasErr && !finalSucceeded {
s.mu.Lock()
s.ctx = context.WithoutCancel(s.ctx)
s.mu.Unlock()
go s.doCleanupFn(s)
}
}()
References
  1. When a cleanup function must be attempted even if its parent context is canceled, use context.WithoutCancel to ensure the operation is not prematurely terminated.

Comment thread storage/pcu.go
Comment thread storage/pcu.go
@cpriti-os
cpriti-os requested a review from krishnamd-jkp June 10, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants